﻿using System;
using System.Windows.Forms;

namespace RegistryGUI
{
    public partial class AddForm : Form
    {
        public string Var;
        public string Value;
        public AddForm()
        {
            InitializeComponent();
        }
        public void SetText(string name, string value)
        {
            textBox_Var.Text = name;
            textBox_Value.Text = value;
        }
        public void SetSelectVar()
        {
            textBox_Var.Focus();
            textBox_Var.SelectAll();
            this.ActiveControl = textBox_Var;//激活当前控件
        }
        public void SetSelectValue()
        {
            textBox_Value.Focus();
            textBox_Value.SelectAll();
            this.ActiveControl = textBox_Value;//激活当前控件
        }
        public void SetVarReadOnly()
        {
            textBox_Var.ReadOnly = true;
        }

        private void Button_Dir_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderBrowserDialog选择目录 = new FolderBrowserDialog();
            if (folderBrowserDialog选择目录.ShowDialog() == DialogResult.OK && folderBrowserDialog选择目录.SelectedPath != string.Empty)
            {
                textBox_Value.Text = folderBrowserDialog选择目录.SelectedPath;//得到选中目录
            }
        }

        private void Button_File_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog选择文件 = new OpenFileDialog
            {
                Title = "打开"
            };
            if (openFileDialog选择文件.ShowDialog() == DialogResult.OK && openFileDialog选择文件.FileName != string.Empty)
            {
                textBox_Value.Text = openFileDialog选择文件.FileName;//得到选中文件
            }
        }

        private void Button_OK_Click(object sender, EventArgs e)
        {
            Var = textBox_Var.Text;
            Value = textBox_Value.Text;
            if (Var == "" || Value == null)
            {
                MessageBox.Show("变量名不能为空", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                return;
            }
            this.DialogResult = DialogResult.OK;
            this.Hide();
        }

        private void Button_Cancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Hide();
        }
    }
}
